using System;
using Dalamud.Game.ClientState.Objects.SubKinds;
using Lumina.Excel.Sheets;

namespace Dalamud_UserUpdate
{
    public class FFXIVPlayObjectUser
    {
        public string? id;
        public ulong ContentId;

        public string? nickname;

        public string? update_play_id;

        public string server_name;

        public int world_type;

        public string? job;

        public int level;

        public string? locale;


        public string? record_time;

        public FFXIVPlayObjectUser()
        {
        }


        public override bool Equals(object? obj)
        {
            if (obj == null)
                return false;
            if (obj == this)
                return true;
            if (this.GetType() != obj.GetType()) //步骤3
                return false;

            FFXIVPlayObjectUser ffxivPlayObjectUser = (FFXIVPlayObjectUser)obj;
            return id != null && id.Equals(ffxivPlayObjectUser.id);
        }

        public static FFXIVPlayObjectUser GetFfxivPlayObjectUser(IPlayerCharacter localPlayer, IPlayerCharacter gameObject, World world, TerritoryType territory)
        {

            FFXIVPlayObjectUser ffxivPlayObjectUser = new FFXIVPlayObjectUser();
            ffxivPlayObjectUser.id = gameObject.GameObjectId.ToString("X");
            ffxivPlayObjectUser.update_play_id = localPlayer.GameObjectId.ToString("X");
            ffxivPlayObjectUser.job = gameObject.ClassJob.Value.Name.ToString();
            ffxivPlayObjectUser.nickname = gameObject.Name.ToString();
            ffxivPlayObjectUser.server_name = world.Name.ToString();
            ffxivPlayObjectUser.level = gameObject.Level;
            ffxivPlayObjectUser.record_time = DateTime.Now.ToString("s");
            ffxivPlayObjectUser.locale = Utils.GetDutyNameForTerritory(territory);
            ffxivPlayObjectUser.ContentId = Utils.getContentId(gameObject);
            // unsafe
            // {
            //         var characterAddress = (BattleChara*)gameObject.Address;
            //         ffxivPlayObjectUser.ContentId = characterAddress->ContentId;
            //
            // }
            return ffxivPlayObjectUser;
        }
    }
}